﻿using System;
using Microsoft.Xna.Framework;

namespace MyCraft.Minecraft_2D.Blocs
{
    class Cavern : Bloc
    {
        #region Attributs
        int _height;
        Random random;
        #endregion

        #region Constructeur
        public Cavern(double timer)
            : base(timer, 0, false)
        {
            random = new Random((int)timer);
            _height = random.Next(2, 3);
            _id = 8;
            _name = "Cavern";
            _percent = 1;
            _color = Color.Transparent;
        }
        #endregion

        #region Propriétés
        #endregion

        #region Methodes
        public override TypeBloc OnNew(Block map)
        {
            if (map.Position.Y < 150)
                return TypeBloc.None;
            Point p = map.Position;
            if (random.Next(0, 6) != 0)
            {
                foreach (Block b in Map.Range(p, _height - random.Next(-2, 1)))
                {
                    b.IsNew = false;
                    b.Type = TypeBloc.Air;
                }

                //for (int i = map.Position.Y - _height - random.Next(-1, 2); i < map.Position.Y + _height && i < Map.Height; i++)
                //{
                //    p.Y = i;
                //    if (!Map.Exist(p))
                //        break;

                //    Block b = Block.Map[p];
                //    b.IsNew = false;
                //    b.Type = TypeBloc.Air;
                //}
                p.X++;
                p.Y = random.Next(1) + map.Position.Y;
                if (Map.Exist(p))
                {
                    Block b = Block.Map[p];
                    BlocSet.GetSingleton()[TypeBloc.Cavern].OnNew(b);
                    b.IsNew = false;
                }
                return TypeBloc.Air;
            }
            return TypeBloc.None;
        }
        #endregion
    }
}
